﻿using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using WOIM_NET.Music;

namespace WOIM_NET
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            //DataContext = App.ViewModel;
            FavoriteList.DataContext = App.FavoriteViewModel;
            DownloadSongsList.DataContext = App.DownloadedSongViewModel;
        }

        // Load data for the ViewModel Items
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!App.FavoriteViewModel.IsDataLoaded)
            {
                App.FavoriteViewModel.LoadData();
            }

            if (!App.DownloadedSongViewModel.IsDataLoaded)
            {
                App.DownloadedSongViewModel.LoadData();
            }
        }

        private void FavoriteList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var song = (SongModel)FavoriteList.SelectedItem;
            NavigationService.Navigate(new Uri("/PlayPage.xaml?model=song&name=" + song.Name + "&artist=" + song.Artist + "&avatar=" + song.Avatar + "&url=" + song.Url + "&album=" + song.Album + "&linkAlbum=" + song.LinktoAlbum, UriKind.Relative));
        }

        private void DownloadSongsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var song = (SongModel)DownloadSongsList.SelectedItem;
            NavigationService.Navigate(new Uri("/PlayPage.xaml?name=" + song.Name + "&artist=" + song.Artist +"&instrumental=" + song.Instrumental, UriKind.Relative));
        }

        private void Border_MouseLeftButtonDown(object sendser, System.Windows.Input.MouseButtonEventArgs e)
        {
            NavigationService.Navigate(new Uri("/AlbumsPage.xaml", UriKind.Relative));
        }

        private void nowPlaying_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/PlayPage.xaml?model=NowPlaying", UriKind.Relative));
        }

    }
}